package com.xtayfjpk.spring.security.test.schema;

import java.text.SimpleDateFormat;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

public class SimpleDateFormatBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
	
	@Override
	protected Class<?> getBeanClass(Element element) {
		return SimpleDateFormat.class;
	}
	
	@Override
	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		System.out.println("do parse");
		// this will never be null since the schema explicitly requires that a value be supplied
        String pattern = element.getAttribute("pattern");
        builder.addConstructorArgValue(pattern);

        // this however is an optional property
        String lenient = element.getAttribute("lenient");
        if (StringUtils.hasText(lenient)) {
        	builder.addPropertyValue("lenient", Boolean.valueOf(lenient));
        }
	}
}
